package com.grgbanking.it.system.dao.impl;


import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.grgbanking.it.base.BaseDao;
import com.grgbanking.it.system.dao.IRoleDao;
import com.grgbanking.it.system.entity.Role;


/**
 * 系统资源Dao
 * 
 * IRoleDao
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2014-12-11 下午3:36:35
 * 
 * @version 1.0.0
 *
 */
@Repository 
public class RoleDao extends BaseDao<Role, Integer> implements IRoleDao<Role, Integer> { 
    @Autowired  
    public void setMySessionFactory(SessionFactory sessionFactory){  
        super.setSessionFactory(sessionFactory);  
    }

    /**
	 * 获取用户角色
	 * getRolesByUsername
	 * 
	 * @param username
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	@Override
	public List<Role> findByUser(String username) throws Exception {
		StringBuffer sql = new StringBuffer("select r.id,r.name,r.state from role r\n");
		sql.append("where r.id in(select m.role_id from m_user_role m  where m.username='").append(username).append("')");
		return this.findBySQL(sql.toString());
	}
	
}